//
//  YZAboutProductTableViewCell.m
//  kuaiyi
//
//  Created by 刘邓诏初 on 16/5/5.
//
//

#import "YZAboutProductTableViewCell.h"

@interface YZAboutProductTableViewCell()
/// 图标
@property(nonatomic,strong)UIImageView *iconView;
/// 文字标签
@property(nonatomic,strong)UILabel *agreementLabel;
/// 箭头
@property(nonatomic,strong)UIImageView *arrowView;
/// 线条
@property(nonatomic,strong)UIView *lineView;
@end

@implementation YZAboutProductTableViewCell

+ (instancetype)aboutProductTableViewCell:(UITableView *)tableView{
    static NSString *ID=@"aboutCell";
    YZAboutProductTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[YZAboutProductTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self prepareUI];
    }
    return self;
}

- (void)prepareUI{
    // 添加子控件
    [self.contentView addSubview:self.iconView];
    [self.contentView addSubview:self.agreementLabel];
    [self.contentView addSubview:self.arrowView];
    [self.contentView addSubview:self.lineView];
    
    // 禁用 autoresizing
    self.iconView.translatesAutoresizingMaskIntoConstraints = NO;
    self.agreementLabel.translatesAutoresizingMaskIntoConstraints = NO;
    self.arrowView.translatesAutoresizingMaskIntoConstraints = NO;
    self.lineView.translatesAutoresizingMaskIntoConstraints = NO;
    
    // 添加约束
    // 图标
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.iconView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeading multiplier:1 constant:16]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.iconView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.iconView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:23]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.iconView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:20]];
    
    // 文字标签
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.agreementLabel attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.iconView attribute:NSLayoutAttributeTrailing multiplier:1 constant:14]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.agreementLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
    
    // 箭头
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.arrowView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTrailing multiplier:1 constant:-14]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.arrowView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.arrowView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:16]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.arrowView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:16]];
    
    // 线条
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.lineView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.iconView attribute:NSLayoutAttributeLeading multiplier:1 constant:0]];
    
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.lineView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTrailing multiplier:1 constant:-4]];
    
    
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.lineView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1 constant:-1]];
    
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.lineView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:1]];
    
    //    NSLog(@"%@",NSStringFromCGRect(self.lineView.frame));
}

#pragma mark - 懒加载
- (UIImageView *)iconView{
    if (_iconView == nil) {
        _iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"numberDetails"]];
    }
    return _iconView;
}

- (UILabel *)agreementLabel{
    if (_agreementLabel == nil) {
        _agreementLabel = [[UILabel alloc] init];
        _agreementLabel.text = @"用户协议";
        _agreementLabel.font = [UIFont systemFontOfSize:18];
    }
    return _agreementLabel;
}

- (UIImageView *)arrowView{
    if (_arrowView == nil) {
        _arrowView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_step"]];
    }
    return _arrowView;
}

- (UIView *)lineView{
    if (_lineView == nil) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor lightGrayColor];
    }
    return _lineView;
}


@end
